package com.ruoyi.experiment.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.experiment.domain.Firewall;
import com.ruoyi.experiment.service.IFirewallService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 防火墙Controller
 * 
 * @author 邓鑫
 * @date 2023-07-28
 */
@RestController
@RequestMapping("/experiment/firewall")
public class FirewallController extends BaseController
{
    @Autowired
    private IFirewallService firewallService;

    /**
     * 查询防火墙列表
     */
    @PreAuthorize("@ss.hasPermi('experiment:firewall:list')")
    @GetMapping("/list")
    public TableDataInfo list(Firewall firewall)
    {
        startPage();
        List<Firewall> list = firewallService.selectFirewallList(firewall);
        return getDataTable(list);
    }

    /**
     * 导出防火墙列表
     */
    @PreAuthorize("@ss.hasPermi('experiment:firewall:export')")
    @Log(title = "防火墙", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Firewall firewall)
    {
        List<Firewall> list = firewallService.selectFirewallList(firewall);
        ExcelUtil<Firewall> util = new ExcelUtil<Firewall>(Firewall.class);
        util.exportExcel(response, list, "防火墙数据");
    }

    /**
     * 获取防火墙详细信息
     */
    @PreAuthorize("@ss.hasPermi('experiment:firewall:query')")
    @GetMapping(value = "/{firewallId}")
    public AjaxResult getInfo(@PathVariable("firewallId") Long firewallId)
    {
        return success(firewallService.selectFirewallByFirewallId(firewallId));
    }

    /**
     * 新增防火墙
     */
    @PreAuthorize("@ss.hasPermi('experiment:firewall:add')")
    @Log(title = "防火墙", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Firewall firewall)
    {
        return toAjax(firewallService.insertFirewall(firewall));
    }

    /**
     * 修改防火墙
     */
    @PreAuthorize("@ss.hasPermi('experiment:firewall:edit')")
    @Log(title = "防火墙", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Firewall firewall)
    {
        return toAjax(firewallService.updateFirewall(firewall));
    }

    /**
     * 删除防火墙
     */
    @PreAuthorize("@ss.hasPermi('experiment:firewall:remove')")
    @Log(title = "防火墙", businessType = BusinessType.DELETE)
	@DeleteMapping("/{firewallIds}")
    public AjaxResult remove(@PathVariable Long[] firewallIds)
    {
        return toAjax(firewallService.deleteFirewallByFirewallIds(firewallIds));
    }
}
